﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Media.Media3D;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace DsfDemo
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            ratio1.ValueChanged += Ratio1_ValueChanged;
            this.MouseMove += MainWindow_MouseMove;
            DataContext = this;
            new TestWindow().Focus();
        }

        DateTime LastAnimate = DateTime.Now;

        private void MainWindow_MouseMove(object sender, MouseEventArgs e)
        {
            if ((DateTime.Now - LastAnimate).TotalMilliseconds < 120) return;
            var center = new Point(Width / 2, Height / 2);
            var pos = e.GetPosition(this);
            var xTo = (pos.Y - center.Y) / Height * 2 * 30;
            var yTo = (pos.X - center.X) / Width * 2 * 30;
            var animationX = new DoubleAnimation
            {
                To = xTo,
                Duration = new Duration(new TimeSpan(0, 0, 0, 0, 100)),
                //EasingFunction = new QuadraticEase()
            };
            var animationY = new DoubleAnimation
            {
                To = yTo,
                Duration = new Duration(new TimeSpan(0, 0, 0, 0, 100)),
                EasingFunction = new QuadraticEase()
            };
            hori.Value = horibar.Value = rotatebar.Value = (pos.X - center.X) / Width * 2 * 100;
            slide.Value = Math.Abs(hori.Value);
            p2.Value =  hori.Value / 2 + 50;
            label.Content = hori.Value.ToString();
            vertibar.Value = bat.Value = verti2.Value = verti.Value / 2 + 50;
            verti.Value = (center.Y - pos.Y) / Height * 2 * 100;
            axisX.BeginAnimation(AxisAngleRotation3D.AngleProperty, animationX);
            axisY.BeginAnimation(AxisAngleRotation3D.AngleProperty, animationY);
            LastAnimate = DateTime.Now;
            circle.Value += pos.X > center.X ? 10 : -10;
        }

        private void Ratio1_ValueChanged(object sender, EventArgs e)
        {

        }

    }
}
